<%-- 
    Document   : ThemeMgmt
    Created on : Dec 14, 2011, 3:33:22 PM
    Author     : karennyq
--%>

<%@page import="java.util.HashMap"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Theme Management</title>
        <%@include file = "global/admin_include.jsp" %>
        <%
            HashMap am = new HashMap();
            Object obj = request.getSession().getAttribute("accessMap");
            if (obj == null) {
                response.sendRedirect("../admin.jsp");
            } else {
                am = (HashMap) obj;
                if (am.get("T").equals("false")) {
                    response.sendRedirect("accessDenied.jsp");
                }
            }
        %>
        <script type="text/javascript">
            $(document).ready(function(){
                $('#dd').dialog({modal:true});
                $('#dd').dialog('close');
            });
            
            function formatActions(value, row, index){
                return "<input type='button' onclick='getThemeInfo("+row.theme_id+")' value='Edit'/>"; 
            }
            
            function getThemeInfo(theme_id){
                $('#dd').dialog('open');
                $.ajax({
                    type: "POST",
                    url:"../ThemeServlet",
                    data: "action=getThemeInfo"
                        +"&theme_id="+theme_id,
                    dataType: "json",
                    cache: false,
                    success: function(data){
                        if(data.type=='error'){ 
                            alertMsg(data);  
                            $('#dd').dialog('close');
                        }else{
                            $('#theme_id_hidden').val(data.theme_id);
                            $('#theme_position').html(data.position);
                            $('#theme_name').val(data.name);
                            $('#theme_desc').val(data.description);
                            $('#theme_ind_qns').val(data.ind_qns);
                            $('#theme_firm_qns').val(data.firm_qns);
                        }
                    }
                });
            }
            
            function updateTheme(){
                var theme_id = $('#theme_id_hidden').val();
                var theme_name = $('#theme_name').val();
                var theme_desc = $('#theme_desc').val();
                var theme_ind_qns = $('#theme_ind_qns').val();
                var theme_firm_qns = $('#theme_firm_qns').val();
                
                if (theme_id == "" || theme_name == "" || theme_desc == "" || theme_ind_qns == "" || theme_firm_qns == "") {
                    alertMsgStr("Edit Theme", "All fields are required", "error");
                } else {
                    $.ajax({
                        type: "POST",
                        url:"../ThemeServlet",
                        data: "action=updateTheme"
                            +"&theme_id="+theme_id
                            +"&theme_name="+theme_name
                            +"&theme_desc="+theme_desc
                            +"&theme_ind_qns="+theme_ind_qns
                            +"&theme_firm_qns="+theme_firm_qns,
                        dataType: "json",
                        cache: false,
                        success: function(data){
                            if((data.type!='error')){
                                $('#dd').dialog('close'); 
                                $('#tt').datagrid('reload');
                            }
                            alertMsg(data);
                        }
                    });
                }
            }
            
            function closeDD(){
                $('#dd').dialog('close');   
            }
        </script>
    </head>
    <body>
        <div style="border-bottom:1px solid #ccc"><h2>Theme Management</h2></div> 
        <br/>
        <div id="tb" style="padding:5px;height:auto">
            <table width="100%">
                <tr>
                    <td></td>
                </tr>
            </table>
        </div>  
        <div style="height:450px">
            <table id="tt" class="easyui-datagrid" fit="true"
                   url="../ThemeServlet?action=loadTable&industryId=<%=request.getParameter("industry")%>"   
                   toolbar="#tb"  
                   singleSelect="true" fitColumns="true" pagination="false"
                   rownumbers="false">  
                <thead>  
                    <tr> 
                        <th field="theme_id" hidden>ID</th>  
                        <th field="position" width="10%">Position</th>  
                        <th field="name" width="10%">Name</th>
                        <th field="description" width="20%">Short Description</th> 
                        <th field="ind_qns" width="25%">Industry Question</th>
                        <th field="firm_qns" width="25%">Firm Question</th>
                        <th field="actions" width="10%" align="center" formatter="formatActions"></th>
                    </tr>  
                </thead>  
            </table>
        </div>
        <div id="dd" title="Edit Theme" style="width:455px; height:395px">
            <input type="hidden" id="theme_id_hidden" name="theme_id_hidden"/>
            <table>
                <tr>
                    <td colspan="2"><font color="red">All fields are required</font><br/><br/></td>
                </tr>
                <tr>
                    <td>Position:</td>
                    <td><label id="theme_position" name="theme_position"></label></td>
                </tr>
                <tr>
                    <td>Theme Name:</td>
                    <td><input id="theme_name" name="theme_name" type="text"/></td>
                </tr>
                <tr>
                    <td>Short<br/>Description:</td>
                    <td><textarea id="theme_desc" name="theme_desc" rows="1" cols="40"></textarea></td>
                </tr>
                <tr>
                    <td>Industry Level<br/>Question:</td>
                    <td><textarea id="theme_ind_qns" name="theme_ind_qns" rows="4" cols="40"></textarea></td>
                </tr>
                <tr>
                    <td>Firm Level<br/>Question:</td>
                    <td><textarea id="theme_firm_qns" name="theme_firm_qns" rows="4" cols="40"></textarea></td>
                <tr>
                    <td colspan="2" align="center">
                        <br/>
                        <input type="button" onclick="updateTheme()" value="Edit" />
                        <input type="button" onclick="closeDD()" value="Cancel" />
                    </td>
                </tr>
            </table>
        </div>
    </body>
</html>
